library(rmarkdown)
library(tidyverse)
## -- Attaching packages ---------------------------------------------------------------------------------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.4     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.0
## -- Conflicts ------------------------------------------------------------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(Seurat)
## Registered S3 method overwritten by 'spatstat':
##   method     from
##   print.boxx cli
library(Signac)
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
library(ggplot2)
library(GenomeInfoDb)
## Loading required package: BiocGenerics
## Loading required package: parallel
## 
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:parallel':
## 
##     clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
##     clusterExport, clusterMap, parApply, parCapply, parLapply,
##     parLapplyLB, parRapply, parSapply, parSapplyLB
## The following objects are masked from 'package:dplyr':
## 
##     combine, intersect, setdiff, union
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
## 
##     anyDuplicated, append, as.data.frame, basename, cbind, colnames,
##     dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
##     grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
##     order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
##     rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
##     union, unique, unsplit, which.max, which.min
## Loading required package: S4Vectors
## Loading required package: stats4
## 
## Attaching package: 'S4Vectors'
## The following objects are masked from 'package:dplyr':
## 
##     first, rename
## The following object is masked from 'package:tidyr':
## 
##     expand
## The following object is masked from 'package:base':
## 
##     expand.grid
## Loading required package: IRanges
## 
## Attaching package: 'IRanges'
## The following objects are masked from 'package:dplyr':
## 
##     collapse, desc, slice
## The following object is masked from 'package:purrr':
## 
##     reduce
library(patchwork)
set.seed(1234)

nproc=20
library(future)
## 
## Attaching package: 'future'
## The following object is masked from 'package:IRanges':
## 
##     values
## The following object is masked from 'package:S4Vectors':
## 
##     values
## The following object is masked from 'package:rmarkdown':
## 
##     run
options(future.globals.maxSize = 50 * 1024 ^ 3) # for 50 Gb RAM
plan("multiprocess", workers = nproc)
#plan("sequential") #for Rstudio
source(file = here::here("00_parameters.R"))
getwd()
## [1] "/nfsdata/projects/jph712/cutntag_analysis/H3K27ac_VMH_ExptD"
source(file = paste0(projPath,"/00_Rfunctions.R"))
library(BSgenome.Mmusculus.UCSC.mm10)
## Loading required package: BSgenome
## Loading required package: GenomicRanges
## Loading required package: Biostrings
## Loading required package: XVector
## 
## Attaching package: 'XVector'
## The following object is masked from 'package:purrr':
## 
##     compact
## 
## Attaching package: 'Biostrings'
## The following object is masked from 'package:base':
## 
##     strsplit
## Loading required package: rtracklayer
metadata<-readRDS(paste0(projPath,"/", ExptName, "_metadataObject.RDS"))

fragments <- CreateFragmentObject(
  path = paste0(outsPath, "/fragments.tsv.gz"),
  cells=metadata %>% filter(is__cell_barcode==1) %>% pull(barcode),
  validate.fragments = FALSE
)
## Computing hash
### Add GenomeBinMatrix
#add new counts based on bins:

bin_matrix <- GenomeBinMatrix(
  fragments = fragments,
  genome = seqlengths(BSgenome.Mmusculus.UCSC.mm10::BSgenome.Mmusculus.UCSC.mm10),
  binsize = 5000,
  cells=metadata %>% filter(is__cell_barcode==1) %>% pull(barcode)
)
## Extracting reads overlapping genomic regions
dim(bin_matrix)
## [1] 545114    652
bin_matrix<-bin_matrix[which(rowSums(bin_matrix)>10),] #doesn't work in the createSeuratObject?
dim(bin_matrix)
## [1] 363994    652
bin_matrixAssay<- CreateChromatinAssay(
  counts = bin_matrix,
  sep = c(":", "-"),
  fragments = paste0(outsPath, "/fragments.tsv.gz"),
  genome = 'mm10'
)
## Computing hash
signac <- CreateSeuratObject(
  counts = bin_matrixAssay,
  assay = "bin5000",
  min.cells = 1
)

signac<-AddMetaData(signac, metadata %>% column_to_rownames("barcode"))

Annotate and save RDS object:

#See script to create annotations in /nfsdata/projects/jph712/CUTnTag/
annotations<-readRDS("/scratch/kristian/scATAC/signac/EnsDb.Mmusculus.v79_getRangesAnnotation.RDS")

# add the gene information to the object
Annotation(signac) <- annotations
signac<-NucleosomeSignal(signac)
gene.activities <- GeneActivity(signac)
## Extracting gene coordinates
## Extracting reads overlapping genomic regions
# add the gene activity matrix to the Seurat object as a new assay and normalize it
signac[['RNA']] <- CreateAssayObject(counts = gene.activities)
## Warning: Non-unique features (rownames) present in the input matrix, making
## unique
signac <- NormalizeData(
   object = signac,
   assay = 'RNA',
   normalization.method = 'LogNormalize',
   scale.factor = median(signac$nCount_RNA)
 )
## Warning: UNRELIABLE VALUE: Future ('future_lapply-1') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-2') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-3') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-4') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-5') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-6') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-7') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-8') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-9') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-10') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-11') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-12') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-13') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-14') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-15') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-16') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-17') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-18') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-19') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
## Warning: UNRELIABLE VALUE: Future ('future_lapply-20') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
saveRDS(signac, paste0(projPath,"/H3K27ac_Bin5000_SingletsObjectNoAdditionalFiltering.RDS"))
signac
## An object of class Seurat 
## 385972 features across 652 samples within 2 assays 
## Active assay: bin5000 (363994 features, 0 variable features)
##  1 other assay present: RNA

Additional filtering:

VlnPlot(signac, c("nucleosome_signal", "nFeature_bin5000"), log=T)

signac<-
  subset(signac, subset= 
           nucleosome_signal < 3 &
          passed_filters > 10^cutoff_reads_min &  
     enhancer_region_ratio > cutoff_enhancer_ratio &
     passed_filters < 10^cutoff_reads_max
)
signac
## An object of class Seurat 
## 385972 features across 636 samples within 2 assays 
## Active assay: bin5000 (363994 features, 0 variable features)
##  1 other assay present: RNA
saveRDS(signac, paste0(projPath,"/H3K27ac_Bin5000_SingletsObject.RDS"))

Dimensionality reduction

Find top features from bins-> TF-IDF, SVD, UMAP

DefaultAssay(signac) <- 'bin5000'

signac <- FindTopFeatures(signac, min.cutoff = "q5",verbose = T)
#readRDS atac to get top features.
signac
## An object of class Seurat 
## 385972 features across 636 samples within 2 assays 
## Active assay: bin5000 (363994 features, 347061 variable features)
##  1 other assay present: RNA
signac <- RunTFIDF(signac)
## Performing TF-IDF normalization
signac <- RunSVD(signac,
               assay = 'bin5000',
               reduction.key = 'LSIbin_',
               reduction.name = 'lsi_')
## Running SVD
## Scaling cell embeddings
DepthCor(signac, reduction = "lsi_",n = ndim)

RunUMAP

Excluding dimension #1 since it correlates with seq depth.

 # signac <- RunUMAP(signac, reduction = 'lsi_', dims = 2:30, reduction.name = 'lsi_umap', n.start=1000,spread=0.5, min_dist=0.001, n.neighbors = 30)

signac <- RunUMAP(signac, reduction = 'lsi_', dims =c(2:ndim), reduction.name = 'lsi_umap')
## Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric
## To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'
## This message will be shown once per session
## 15:23:13 UMAP embedding parameters a = 0.9922 b = 1.112
## 15:23:13 Read 636 rows and found 29 numeric columns
## 15:23:13 Using Annoy for neighbor search, n_neighbors = 30
## 15:23:14 Building Annoy index with metric = cosine, n_trees = 50
## 0%   10   20   30   40   50   60   70   80   90   100%
## [----|----|----|----|----|----|----|----|----|----|
## **************************************************|
## 15:23:14 Writing NN index file to temp file /tmp/Rtmphi7uJ9/file3b1963452112
## 15:23:14 Searching Annoy index using 20 threads, search_k = 3000
## 15:23:14 Annoy recall = 100%
## 15:23:16 Commencing smooth kNN distance calibration using 20 threads
## 15:23:20 Initializing from normalized Laplacian + noise
## 15:23:20 Commencing optimization for 500 epochs, with 25128 positive edges
## 15:23:24 Optimization finished
DimPlot(signac, reduction = 'lsi_umap', cols=c("polychrome"), label =T) +
  NoLegend() +
  ggtitle("LSIbin_UMAP")

# ggsave("dimPlot_bin_lsi.png")


FeaturePlot(signac, features=c("nCount_bin5000"),reduction = "lsi_umap" )

FeaturePlot(signac, features=c("nFeature_bin5000"),reduction = "lsi_umap" )

FeaturePlot(signac, features=c("passed_filters"),reduction = "lsi_umap" )

#ggsave("dimPlot_bin_lsi_TSS.percentile.png")
DefaultAssay(signac) <- 'bin5000'

signac <- FindNeighbors(object = signac, reduction = 'lsi_', dims =c(2:ndim), force.recalc = T)
## Computing nearest neighbor graph
## Computing SNN
signac <- FindClusters(object = signac, verbose = FALSE, algorithm = 3, resolution=0.4)
## Warning: UNRELIABLE VALUE: Future ('future_lapply-1') unexpectedly generated
## random numbers without specifying argument '[future.]seed'. There is a risk that
## those random numbers are not statistically sound and the overall results might
## be invalid. To fix this, specify argument '[future.]seed', e.g. 'seed=TRUE'.
## This ensures that proper, parallel-safe random numbers are produced via the
## L'Ecuyer-CMRG method. To disable this check, use [future].seed=NULL, or set
## option 'future.rng.onMisuse' to "ignore".
table(signac@meta.data$seurat_clusters)
## 
##   0   1   2   3 
## 367 132  95  42
p_clusters<-DimPlot(signac, reduction = 'lsi_umap', label =T, label.box = T, repel = T) +ggtitle("Clusters based on LSI bin5000")+NoLegend()
p_clusters

# p_dimplotSamples<-DimPlot(signac, reduction = 'lsi_umap', group.by="hash.ID", label =F, label.box = F, repel = T) +ggtitle("Samples based on LSI bin5000")
# p_dimplotSamples
VlnPlot(signac,
            features = c("nCount_bin5000",
                         "nFeature_bin5000",
                         "nCount_HTO",
                         "passed_filters",
                        #"mitochondrial",
                         "enhancer_region_ratio",
                         "nCount_RNA",
                         "nFeature_RNA", 
                      #   "HTO_margin",
                         "blacklist_region_fragments", 
                      "nucleosome_signal"
                         )#, split.by = "is_cellranger_cell_barcode"
)

table(signac$seurat_clusters, signac$is_cellranger_cell_barcode)
##    
##       0   1
##   0  71 296
##   1   3 129
##   2   2  93
##   3   1  41

Make new bam-file for with only called cells

R script to print filtered_cell_barcodes

cells<-
  signac@meta.data %>% 
  #as_tibble() %>%
  rownames_to_column("barcode") %>%
    filter(is__cell_barcode=="1") %>% 
  dplyr::select(barcode, seurat_clusters)

cells$seurat_clusters<-paste0("BinCluster",cells$seurat_clusters)

write_tsv(x = cells, file=paste0(projPath,"/bam/FilteredCellBarcodes_BinClusters.tsv"), col_names = FALSE)

Save RDS object:

saveRDS(signac, "H3K27ac_BinClusteredObject.RDS")
markers<-
  c(
"Agrp", "Npy", "Sst",
"Pomc", 
"Meis2", "Tbr1", "Zfhx4", 
"Nr5a1", "Ghrh", "Otp", "Oxt",
"Cck", "Ebf3",
 "Slc32a1", "Slc17a6",
"Gfap", 
"Satb2"
  )


DefaultAssay(signac) <- 'RNA'

p_markers<-FeaturePlot(
  object = signac,
  features = c(markers, "nCount_bin5000"),
  pt.size = 0.1,
  max.cutoff = 'q90',
  ncol = floor(length(markers)/5)
) & NoLegend() & NoAxes()

p_markers

p_vln_markers<-VlnPlot(signac, features=markers, group.by="seurat_clusters")
p_vln_markers

DefaultAssay(signac) <- 'bin5000'

da_bins <- FindAllMarkers(
  object = signac, 
  min.diff.pct = 0.1,
  logfc.threshold = 0.1,
  test.use = 'LR'
)

da_binsGR <- makeGRangesFromDataFrame(separate(da_bins, col=gene, sep="-",  c("Chr", "Start", "End")))
elementMetadata(da_binsGR)<-da_bins


blacklist.df = read_tsv(file="/projects/jph712/CUTnTag/H3K27ac_ARC_scCUTnTAG_B/deepTools/mm10-blacklist.v3.bed" ,col_names = F) 
blacklist.gr=GenomicRanges::GRanges(seqnames=blacklist.df$X1,
               ranges=IRanges(start=as.numeric(blacklist.df$X2),
                              end=as.numeric(blacklist.df$X3)))
simpleGR_diff<-GenomicRanges::setdiff(da_binsGR, blacklist.gr, ignore.strand=TRUE)

da_binsGR_white<-subsetByOverlaps(da_binsGR,simpleGR_diff, ignore.strand=TRUE)

filtered_DAbins.df<- 
  da_binsGR_white@elementMetadata %>% 
  as_tibble() %>% 
  filter(p_val_adj<0.1 & avg_logFC>0.25 |p_val_adj<0.1 &  -0.25>avg_logFC) %>% 
  distinct(gene, .keep_all=T) %>%
  group_by(cluster) %>% 
  arrange(avg_logFC) %>%
  dplyr::select(gene, cluster, avg_logFC,p_val_adj, everything())

 
########

closest <- ClosestFeature(signac,
  regions = filtered_DAbins.df$gene,
  )
  
filtered_DAbins.df<-left_join(filtered_DAbins.df, closest, by=c("gene"= "query_region"))

#write DA bins to excel file
writexl::write_xlsx(filtered_DAbins.df, path = "DiffAcetylatedBINS_FindAll.xlsx", col_names = TRUE)

go to chapter 06.

sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Red Hat Enterprise Linux
## 
## Matrix products: default
## BLAS/LAPACK: /usr/lib64/libopenblas-r0.3.3.so
## 
## locale:
##  [1] LC_CTYPE=C                 LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats4    parallel  stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] BSgenome.Mmusculus.UCSC.mm10_1.4.0 BSgenome_1.58.0                   
##  [3] rtracklayer_1.50.0                 Biostrings_2.58.0                 
##  [5] XVector_0.30.0                     GenomicRanges_1.42.0              
##  [7] future_1.20.1                      patchwork_1.1.0                   
##  [9] GenomeInfoDb_1.26.2                IRanges_2.24.1                    
## [11] S4Vectors_0.28.1                   BiocGenerics_0.36.0               
## [13] Signac_1.1.0                       Seurat_3.2.2                      
## [15] forcats_0.5.0                      stringr_1.4.0                     
## [17] dplyr_1.0.2                        purrr_0.3.4                       
## [19] readr_1.4.0                        tidyr_1.1.2                       
## [21] tibble_3.0.4                       ggplot2_3.3.2                     
## [23] tidyverse_1.3.0                    rmarkdown_2.5                     
## 
## loaded via a namespace (and not attached):
##   [1] rappdirs_0.3.1              SnowballC_0.7.0            
##   [3] GGally_2.0.0                bit64_4.0.5                
##   [5] knitr_1.30                  irlba_2.3.3                
##   [7] DelayedArray_0.16.0         data.table_1.13.4          
##   [9] rpart_4.1-15                RCurl_1.98-1.2             
##  [11] AnnotationFilter_1.14.0     generics_0.1.0             
##  [13] GenomicFeatures_1.42.1      cowplot_1.1.0              
##  [15] RSQLite_2.2.1               RANN_2.6.1                 
##  [17] bit_4.0.4                   spatstat.data_1.5-2        
##  [19] xml2_1.3.2                  lubridate_1.7.9.2          
##  [21] httpuv_1.5.4                SummarizedExperiment_1.20.0
##  [23] assertthat_0.2.1            xfun_0.19                  
##  [25] hms_0.5.3                   evaluate_0.14              
##  [27] promises_1.1.1              fansi_0.4.1                
##  [29] progress_1.2.2              dbplyr_2.0.0               
##  [31] readxl_1.3.1                igraph_1.2.6               
##  [33] DBI_1.1.0                   htmlwidgets_1.5.2          
##  [35] reshape_0.8.8               ellipsis_0.3.1             
##  [37] RSpectra_0.16-0             backports_1.2.0            
##  [39] biomaRt_2.46.0              deldir_0.2-3               
##  [41] MatrixGenerics_1.2.0        vctrs_0.3.5                
##  [43] Biobase_2.50.0              here_1.0.0                 
##  [45] ensembldb_2.14.0            ROCR_1.0-11                
##  [47] abind_1.4-5                 withr_2.3.0                
##  [49] ggforce_0.3.2               checkmate_2.0.0            
##  [51] sctransform_0.3.1           GenomicAlignments_1.26.0   
##  [53] prettyunits_1.1.1           goftest_1.2-2              
##  [55] cluster_2.1.0               lazyeval_0.2.2             
##  [57] crayon_1.3.4                pkgconfig_2.0.3            
##  [59] labeling_0.4.2              tweenr_1.0.1               
##  [61] nlme_3.1-150                ProtGenerics_1.22.0        
##  [63] nnet_7.3-14                 rlang_0.4.9                
##  [65] globals_0.14.0              lifecycle_0.2.0            
##  [67] miniUI_0.1.1.1              BiocFileCache_1.14.0       
##  [69] modelr_0.1.8                rsvd_1.0.3                 
##  [71] dichromat_2.0-0             cellranger_1.1.0           
##  [73] rprojroot_2.0.2             polyclip_1.10-0            
##  [75] matrixStats_0.57.0          lmtest_0.9-38              
##  [77] graph_1.68.0                Matrix_1.2-18              
##  [79] ggseqlogo_0.1               zoo_1.8-8                  
##  [81] reprex_0.3.0                base64enc_0.1-3            
##  [83] ggridges_0.5.2              png_0.1-7                  
##  [85] viridisLite_0.3.0           bitops_1.0-6               
##  [87] KernSmooth_2.23-18          blob_1.2.1                 
##  [89] parallelly_1.21.0           jpeg_0.1-8.1               
##  [91] scales_1.1.1                memoise_1.1.0              
##  [93] magrittr_2.0.1              plyr_1.8.6                 
##  [95] ica_1.0-2                   zlibbioc_1.36.0            
##  [97] compiler_4.0.2              RColorBrewer_1.1-2         
##  [99] fitdistrplus_1.1-3          Rsamtools_2.6.0            
## [101] cli_2.2.0                   listenv_0.8.0              
## [103] pbapply_1.4-3               ps_1.5.0                   
## [105] htmlTable_2.1.0             Formula_1.2-4              
## [107] MASS_7.3-53                 mgcv_1.8-33                
## [109] tidyselect_1.1.0            stringi_1.5.3              
## [111] yaml_2.2.1                  askpass_1.1                
## [113] latticeExtra_0.6-29         ggrepel_0.8.2              
## [115] grid_4.0.2                  VariantAnnotation_1.36.0   
## [117] fastmatch_1.1-0             tools_4.0.2                
## [119] future.apply_1.6.0          rstudioapi_0.13            
## [121] foreign_0.8-80              lsa_0.73.2                 
## [123] gridExtra_2.3               farver_2.0.3               
## [125] Rtsne_0.15                  digest_0.6.27              
## [127] BiocManager_1.30.10         shiny_1.5.0                
## [129] Rcpp_1.0.5                  broom_0.7.2                
## [131] later_1.1.0.1               RcppAnnoy_0.0.17           
## [133] OrganismDbi_1.32.0          httr_1.4.2                 
## [135] AnnotationDbi_1.52.0        ggbio_1.38.0               
## [137] biovizBase_1.38.0           colorspace_2.0-0           
## [139] rvest_0.3.6                 XML_3.99-0.5               
## [141] fs_1.5.0                    tensor_1.5                 
## [143] reticulate_1.18             splines_4.0.2              
## [145] uwot_0.1.9                  RBGL_1.66.0                
## [147] RcppRoll_0.3.0              spatstat.utils_1.17-0      
## [149] plotly_4.9.2.1              xtable_1.8-4               
## [151] jsonlite_1.7.2              spatstat_1.64-1            
## [153] R6_2.5.0                    Hmisc_4.4-2                
## [155] pillar_1.4.7                htmltools_0.5.0            
## [157] mime_0.9                    glue_1.4.2                 
## [159] fastmap_1.0.1               BiocParallel_1.24.1        
## [161] codetools_0.2-18            lattice_0.20-41            
## [163] curl_4.3                    leiden_0.3.6               
## [165] openssl_1.4.3               survival_3.2-7             
## [167] munsell_0.5.0               GenomeInfoDbData_1.2.4     
## [169] haven_2.3.1                 reshape2_1.4.4             
## [171] gtable_0.3.0